import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Test from '@/pages/Test'
//将VueRouter原型上的push保存一份
const originalPush=VueRouter.prototype.push;
//修改VueRouter原型上的push,用于解决重复跳转报错
VueRouter.prototype.push=function(location,okCallBack,errCallBack){
    if(okCallBack===undefined && errCallBack===undefined){
        return originalPush.call(this,location).catch(()=>{});
    }else{
        return originalPush.call(this,location,okCallBack,errCallBack)
    }
}

export default new VueRouter({
    mode:'history',
    routes:[
        {
            name:'home',
            path:'/home',
            component: Home,
            meta: {showFooter:true}
        },
        {
            name:'login',
            path:'/login',
            component: Login,
            meta: {showFooter:false}
        },
        {
            name:'register',
            path:'/register',
            component: Register,
            meta: {showFooter:false}
        },
        {
            name:'search',
            path:'/search',
            component: Search,
            meta: {showFooter:true}

        },
        {
            name:'test',
            path:'/test',
            component: Test
        },
        {
            path:'/',
            redirect:'/home'
        }
    ]
})